/* $Id: AbstractFormatter.java 115 2011-02-02 21:16:35Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.gui;

import java.util.List;

import alt.djudge.frontend.server.datatypes.AbstractEntry;


public abstract class AbstractFormatter<T extends AbstractEntry> extends HtmlToolkit
{
	private String getRowStyle(T entry)
	{
		if (entry.getDeleted())
			return "text-decoration: line-through;";
		/*if (!entry.getActive())
			return "text-decoration: overline;";*/
		return getCustomRowClass(entry);
	}

	protected void addRow(T entry)
	{
		// start row
		startTableRow(getTrHtmlClass(), getRowStyle(entry));
		
		// add row data
		addClassData(entry);
		
		// end row
		endTableRow();
	}
	
	public String format(List<T> entries)
	{
		startTable(getTableClass(), getTableWidth(), getTableStyle(), getTableBorder());

		// headers
		addHeaders();

		// adding rows
		for (T entry : entries)
			addRow(entry);

		// finish table
		endTable();
		
		return getResult();
	}

	protected void addHeaders()
	{
		// start of `building header'
		startTableRow(getTrHtmlClass());
		
		// entry-specific headers
		addClassHeaders();
		
		// end of `building header'
		endTableRow();
	}
	
	protected String getTrHtmlClass()
	{
		return null;
	}
	
	protected String getTdHtmlClass()
	{
		return null;
	}
	
	protected String getThHtmlClass()
	{
		return null;
	}
	
	protected String getTableWidth()
	{
		return "90%";
	}
	
	protected String getTableClass()
	{
		return "b1";
	}
	
	protected String getTableStyle()
	{
		return null;
	}
	
	protected String getTableBorder()
	{
		return "1";
	}

	protected abstract String getCustomRowClass(T entry);
	
	protected abstract void addClassHeaders();
	
	protected abstract void addClassData(T entry);
}
